/**
 * Module Dependencies.
 */
var gulp = require("gulp");//创建 gulp模块
var uglify = require("gulp-uglify");//创建js混淆压缩 模块
var clean_css = require("gulp-clean-css");　//创建 css混淆压缩模块
var gulp_concat = require('gulp-concat');  //创建 文件合并模块
var rename = require('gulp-rename');
var jshint = require('gulp-jshint');

gulp.task('jshint', function () {
    return gulp.src('js/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('minifycss', function () {
    return gulp.src([
        "../src/main/resources/static/lib/bootstrap/css/bootstrap.min.css",
        "../src/main/resources/static/lib/plugins/font-awesome/css/font-awesome.min.css",
        "../src/main/resources/static/lib/plugins/ionicons/css/ionicons.min.css",
        "../src/main/resources/static/lib/admin/css/AdminLTE.min.css",
        "../src/main/resources/static/lib/admin/css/skins/skin-blue.min.css",
        "../src/main/resources/static/lib/plugins/selectize/css/selectize.css",
        "../src/main/resources/static/lib/plugins/messenger/css/messenger-theme-air.css",
        "../src/main/resources/static/lib/plugins/messenger/css/messenger.css",
        "../src/main/resources/static/lib/plugins/datatables/dataTables.bootstrap.css",
        "../src/main/resources/static/lib/plugins/bootstrap-modal/css/bootstrap-modal.css",
        "../src/main/resources/static/lib/plugins/bootstrap-modal/css/bootstrap-modal-bs3patch.css",
        "../src/main/resources/static/lib/plugins/jquery-validation/1.11.1/jquery.validate.min.js",
    ])    //需要操作的文件
        .pipe(gulp_concat('app.min.css'))    //合并所有js到min.js
        .pipe(clean_css())
        .pipe(gulp.dest('../src/main/resources/static/build/css'))       //输出到文件夹
});

//压缩，合并 js
gulp.task('minifyjs', function () {
    return gulp.src([
        "../src/main/resources/static/lib/plugins/jquery-2.2.3.min.js",
        "../src/main/resources/static/lib/bootstrap/js/bootstrap.min.js",
        "../src/main/resources/static/lib/admin/js/app.min.js",
        "../src/main/resources/static/lib/plugins/jquery.cookie.js",
        "../src/main/resources/static/lib/plugins/jstz.min.js",
        "../src/main/resources/static/lib/plugins/localforage.min.js",
        "../src/main/resources/static/lib/plugins/lodash.min.js",
        "../src/main/resources/static/lib/plugins/messenger/js/messenger.min.js",
        "../src/main/resources/static/lib/plugins/selectize/js/standalone/selectize.min.js",
        "../src/main/resources/static/lib/plugins/datatables/jquery.dataTables.min.js",
        "../src/main/resources/static/lib/plugins/datatables/dataTables.bootstrap.min.js",
        "../src/main/resources/static/lib/plugins/bootstrap-modal/js/bootstrap-modal.js",
        "../src/main/resources/static/lib/plugins/bootstrap-modal/js/bootstrap-modalmanager.js",
        "../src/main/resources/static/lib/plugins/jquery-validation/1.11.1/jquery.validate.min.js",
    ])//需要操作的文件
        .pipe(gulp_concat('app.min.js'))    //合并所有js到main.js
        .pipe(uglify())
        .pipe(gulp.dest('../src/main/resources/static/build/js'))       //输出到文件夹
});

gulp.task('move', function () {
    gulp.src([
        "../src/main/resources/static/lib/bootstrap/fonts/**",
        "../src/main/resources/static/lib/plugins/font-awesome/fonts/**",
    ])
        .pipe(gulp.dest('../src/main/resources/static/build/fonts'))       //输出到文件夹
});
//默认命令，在cmd中输入gulp后，执行的就是这个任务(压缩js需要在检查js之后操作)
gulp.task('default', ["jshint"], function () {
    gulp.start('minifyjs', "minifycss", "move");
});
